(function (vc) {
    vc.extends({
        data: {
            finishHousekeepingPoolInfo: {
                poolId: '',
                servId: '',
                context: '',
                fees: [],
                beforeRepairPhotos: [],
                afterRepairPhotos: []
            }
        },
        _initMethod: function () {
            $that.finishHousekeepingPoolInfo.poolId = vc.getParam('poolId');
            $that.finishHousekeepingPoolInfo.servId = vc.getParam('servId');
            $that._loadPoolFees();
        },
        _initEvent: function () {
            vc.on("finishHousekeepingPoolInfo", "notifyUploadBeforeReapirImage", function (_param) {
                $that.finishHousekeepingPoolInfo.beforeRepairPhotos = [];
                _param.forEach((item) => {
                    $that.finishHousekeepingPoolInfo.beforeRepairPhotos.push({
                        'photo': item
                    })
                })
            });
            vc.on("finishHousekeepingPoolInfo", "notifyUploadAfterReapirImage", function (_param) {
                $that.finishHousekeepingPoolInfo.afterRepairPhotos = [];
                _param.forEach((item) => {
                    $that.finishHousekeepingPoolInfo.afterRepairPhotos.push({
                        'photo': item
                    })
                })
            });
            vc.on('finishHousekeepingPool', 'chooseHousekeepingServFee', function (_data) {
                _data.state = '1001';
                _data.price = _data.feePrice;
                _data.payPrice = _data.feePrice;
                $that.finishHousekeepingPoolInfo.fees.push(_data);
            });
        },
        methods: {
            finishHousekeepingPoolValidate() {
                return vc.validate.validate({
                    finishHousekeepingPoolInfo: $that.finishHousekeepingPoolInfo
                }, {
                    'finishHousekeepingPoolInfo.poolId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "报修单不能为空"
                        }
                    ],
                    'finishHousekeepingPoolInfo.context': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "处理意见不能为空"
                        }
                    ]
                });
            },
            _finishHousekeepingPoolInfo: function () {
                if (!$that.finishHousekeepingPoolValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                let _fees = [];
                $that.finishHousekeepingPoolInfo.fees.forEach(item => {
                    if (item.state == '1001' && !item.cartId) {
                        _fees.push(item);
                    }
                })
                let _data = {
                    shopId: vc.getCurrentCommunity().shopId,
                    poolId: $that.finishHousekeepingPoolInfo.poolId,
                    context: $that.finishHousekeepingPoolInfo.context,
                    fees: _fees
                }
                vc.http.apiPost(
                    '/housekeeping.servPoolFinish',
                    JSON.stringify(_data),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            $that._back();
                            vc.toast(_json.msg);
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    }
                );
            },
            // 移除费用
            _deleteFee: function (index) {
                $that.finishHousekeepingPoolInfo.fees.splice(index, 1);
            },
            _loadPoolFees: function () {
                let _param = {
                    params: {
                        page: 1,
                        row: 50,
                        poolId: $that.finishHousekeepingPoolInfo.poolId,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                }
                //发送get请求
                vc.http.apiGet('/storeOrder.queryStoreOrderCartFee',
                    _param,
                    function (json, res) {
                        let _vipUserObj = JSON.parse(json);
                        $that.finishHousekeepingPoolInfo.fees = _vipUserObj.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            // 返回
            _back: function () {
                vc.goBack();
            },
            clearFinishRepairInfo: function () {
                $that.finishHousekeepingPoolInfo = {
                    poolId: '',
                    servId: '',
                    repairType: '',
                    context: '',
                    feeFlag: '200',
                    repairObjType: '',
                    publicArea: '',
                    repairChannel: '',
                    maintenanceTypes: [],
                    maintenanceType: '',
                    totalPrice: 0,
                    choosedGoodsList: []
                };
            },
            _chooseServFees: function () {
                vc.emit('chooseHousekeepingServFee', 'openChooseHousekeepingServFeeModel', {
                    servId: $that.finishHousekeepingPoolInfo.servId
                });
            }
        }
    });
})(window.vc);
